package com.wyx.videoplay.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.wyx.videoplay.AddCustormActivity;
import com.wyx.videoplay.R;
import com.wyx.videoplay.itemdecoration.SimplePaddingDecoration;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * A simple {@link Fragment} subclass.
 */
public class VideoFragment extends Fragment {


    private TextView tvRightText;
    private TextView tvTitle;
    private RecyclerView mRvVideo;

    // TODO: Rename and change types and number of parameters
    public static VideoFragment newInstance() {
        VideoFragment fragment = new VideoFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_video_manger, container, false);
        initView(view);
        initData();
        return view;
    }

    private void initData() {


    }

    private void initView(View view) {
        view.findViewById(R.id.iv_back_layout_top).setVisibility(View.INVISIBLE);
        tvRightText = view.findViewById(R.id.iv_option2_layout_top);
        tvTitle = view.findViewById(R.id.tv_title_layout_top);
        tvTitle.setText("客户信息");
        tvRightText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), AddCustormActivity.class));
            }
        });

        mRvVideo = view.findViewById(R.id.rv_video);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRvVideo.addItemDecoration(new SimplePaddingDecoration(getActivity()));
        mRvVideo.setLayoutManager(linearLayoutManager);

        List<String> datas=new ArrayList<>();
        datas.add("a");
        datas.add("a");
        datas.add("b");
        datas.add("a");

        CommonAdapter<String> commonAdapter = new CommonAdapter<String>(getActivity(), R.layout.vedio_item_layout, datas) {


            @Override
            protected void convert(ViewHolder holder, String s, int position) {
                if(s.equals("b")){
                    holder.setText(R.id.tv_title,"未知视频");
                }else {
                    holder.setText(R.id.tv_title,"客户视频");
                }
            }
        };
        mRvVideo.setAdapter(commonAdapter);

        commonAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int i) {



            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                return false;
            }
        });


    }
}
